/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DiagnosPanel.java
 *
 * Created on 07.07.2009, 14:51:10
 */

package ru.vsu.cs.piit.vokod.view.panels;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import javax.swing.JComboBox;
import ru.vsu.cs.piit.vokod.TableModels.CBModel;
import ru.vsu.cs.piit.vokod.controller.Controller;
import ru.vsu.cs.piit.vokod.controller.Maps;
import ru.vsu.cs.piit.vokod.model.Diagnos;
import ru.vsu.cs.piit.vokod.model.GroupOfDiagnosis;

/**
 *
 * @author Галчонок
 */
public class DiagnosPanel extends javax.swing.JPanel {
    Diagnos diagnos = new Diagnos();

    /** Creates new form DiagnosPanel */
    public DiagnosPanel() {
        this(new Diagnos());
    }

    public DiagnosPanel(Diagnos diagnos) {
        initComponents();
        this.diagnos = diagnos;
        setValues();
        AddActions();
        this.setSize(this.getPreferredSize());
    }

    private void AddActions(){
        tfCode.addFocusListener(new FocusListener() {

            public void focusGained(FocusEvent e) {}

            public void focusLost(FocusEvent e) {
                diagnos.setCode(tfCode.getText());
            }
        });

        cbGroup.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                diagnos.setGroupOfDiagnos((GroupOfDiagnosis)cbGroup.getModel().getSelectedItem());
            }
        });

        jAddGroupOfDgnBtn.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                Controller.getInstance().addGroupOfDiagnoses();
            }
        });
    }

    void setValues(){
        tfCode.setText(diagnos.getCode());
        cbGroup.getModel().setSelectedItem(diagnos.getGroupOfDiagnos());
    }

    public Diagnos getDiagnos(){
        return diagnos;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        dateChooserCombo1 = new datechooser.beans.DateChooserCombo();
        jLabel1 = new javax.swing.JLabel();
        tfCode = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        cbGroup = new JComboBox(new CBModel(Maps.getGroupOfDiagnosisesList()));
        jAddGroupOfDgnBtn = new javax.swing.JButton();

        jLabel1.setText("Код диагноза");

        jLabel2.setText("Группа диагнозов");

        jAddGroupOfDgnBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ru/vsu/cs/piit/vokod/resources/add.gif"))); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tfCode, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(cbGroup, 0, 193, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jAddGroupOfDgnBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tfCode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jAddGroupOfDgnBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbGroup, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cbGroup;
    private datechooser.beans.DateChooserCombo dateChooserCombo1;
    private javax.swing.JButton jAddGroupOfDgnBtn;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField tfCode;
    // End of variables declaration//GEN-END:variables

}
